//
//  ViewController.m
//  逆向传值(通知)
//
//  Created by whz on 2017/7/10.
//  Copyright © 2017年 王鸿政_whz. All rights reserved.
//

#import "ViewController.h"
#import "ViewController2.h"

@interface ViewController ()

@property(nonatomic, strong)UILabel *label1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createUI];
}

- (void)createUI {
    
    self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(self.view.center.x-50, self.view.center.y-25, 100, 50)];
    [self.view addSubview:_label1];
    _label1.text = @"PUSH";
    _label1.textAlignment = NSTextAlignmentCenter;
    _label1.textColor = [UIColor redColor];
    _label1.font = [UIFont systemFontOfSize:20 weight:5];
    _label1.userInteractionEnabled = YES;
    [_label1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(push)]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveValue:) name:@"sendValue" object:nil]; // 接收者需要注册通知
}

- (void)push {
    
    ViewController2 *vc2 = [ViewController2 new];
    vc2.str2 = _label1.text;
    
    [self presentViewController:vc2 animated:YES completion:nil];
}

/**
 监听通知方法
 */
- (void)recieveValue:(NSNotification *)notification {

    self.label1.text = notification.userInfo[@"value"];
}

/**
 移除通知
 */
- (void)dealloc {

    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
